<template>
  <view class="index">
    <view class="jtop">
      <view class="status_bar"><!-- 这里是状态栏 --></view>
      <view class="jtop_l" @tap="navigateBack">取消</view>
      <view class="jtop_c">新建项目</view>
      <view
        class="jtop_r"
        :style="{ opacity: name ? '1' : '.6' }"
        @click="jsave"
        >确定</view
      >
    </view>

    <view class="tophr"></view>

    <view class="addi">
      <text>项目名称</text>
      <input
        type="text"
        placeholder="请输入项目名称"
        :value="name"
        @input="onKeyInput_o"
        placeholder-style="color:#CCCCCC"
      />
    </view>

    <view class="addi ">
      <view class="addbi" style="background:none">
        <text
          style="margin:0;z-index: 999999;
    position: relative;"
          >项目所在地</text
        >
        <image src="../../static/img/jt.png" @confirm="confirm2"></image>
        <!-- <text class="addbir" >项目所在地</text> -->

        <pickerAddress
          @change="change"
          style="margin-top:22rpx"
          :placeholder="mrwz"
        ></pickerAddress>
      </view>
    </view>

    <view class="addb">
      <e-picker-plus
        endRule="2040-12-31"
        class="addbi"
        @confirm="confirm"
        mode="YMD"
      >
        <text class="addbil">项目开始时间</text>
        <image src="../../static/img/jt.png" @confirm="confirm"></image>
        <text class="addbir" @confirm="confirm">{{ beginDate }}</text>
      </e-picker-plus>
      <e-picker-plus
        endRule="2040-12-31"
        class="addbi"
        @confirm="confirm2"
        mode="YMD"
      >
        <text class="addbil">项目结束时间</text>
        <image src="../../static/img/jt.png" @confirm="confirm2"></image>
        <text class="addbir" @confirm="confirm2">{{ endDate }}</text>
      </e-picker-plus>
    </view>

    <view class="addi">
      <text>项目描述</text>
      <textarea
        auto-height="true"
        style="min-height: 150rpx;"
        maxlength="-1"
        placeholder-style="color:#CCCCCC"
        placeholder="请输入项目描述"
        :value="descn"
        @input="onKeyInput_t"
      />
    </view>
  </view>
</template>

<script>
import request from '@/common/request.js';
import pickerAddress from 'components/biaofun-region/biaofun-region.vue';
import { mapState } from 'vuex';

export default {
  components: {
    pickerAddress,
  },

  computed: mapState(['forcedLogin', 'hasLogin', 'userName']),
  data() {
    return {
      repeat_click: true,
      name: '',
      beginDate: '',
      endDate: '',
      corpId: uni.getStorageSync('user').corpBaseInfoResponse.id,
      descn: '',
      isLoading: false,
      txt: [],
      txtid: [],
      mrwz: '请选择',
    };
  },
  methods: {
    change(data) {
      console.log(data);
      this.txt = [data[0].name, data[1].name, data[2].name];
      this.txtid = [data[0].id, data[1].id, data[2].id];

      console.log('txt', this.txt);
      console.log('txt', this.txtid);

      // this.txt = data.data.join('')
      // console.log(data.data.join(''))
    },

    confirm(e) {
      console.log(e);
      this.beginDate = e.result;
    },

    confirm2(e) {
      console.log(e);
      this.endDate = e.result;
    },
    onKeyInput_o: function(event) {
      this.name = event.detail.value;
    },
    onKeyInput_t: function(event) {
      this.descn = event.detail.value;
    },

    jsave() {
      if (!this.repeat_click) {
        return;
      }
      this.repeat_click = false;
      if (!this.corpId) {
        this.repeat_click = true;
        uni.showToast({
          title: '请在我的 - 设置 - 添加企业后再新增',
          icon: 'none',
        });
        return;
      }

      if (!this.name) {
        this.repeat_click = true;
        uni.showToast({
          title: '请输入项目名称',
          icon: 'none',
        });
        return;
      }

      // if(!this.beginDate){
      // 						this.repeat_click = true;
      //uni.showToast({
      // 		title: '请输入项目开始时间',
      // 		icon: 'none'
      // 	})
      // 	return
      // }

      // if(!this.endDate){
      // 						this.repeat_click = true;
      //					uni.showToast({
      // 		title: '请输入项目结束时间',
      // 		icon: 'none'
      // 	})
      // 	return
      // }

      // if(!this.descn){
      // 						this.repeat_click = true;
      //uni.showToast({
      // 		title: '请输入项目描述',
      // 		icon: 'none'
      // 	})
      // 	return
      // }

      request({
        url: '/ucenter/project',
        data: {
          corpId: this.corpId,
          beginDate: this.beginDate,
          endDate: this.endDate,
          name: this.name,
          descn: this.descn,
          provinceId: this.txtid[0],
          cityId: this.txtid[1],
          districtId: this.txtid[2],
        },

        method: 'POST',
        success: openIdRes => {
          console.log(openIdRes);
          if (openIdRes.data.success == true) {
            wx.showToast({
              title: '添加成功',
              icon: 'none',
              duration: 1000,
              success: function() {
                setTimeout(function() {
                  uni.navigateBack();
                }, 1500);
              },
            });

            // uni.navigateBack()
          } else {
            this.repeat_click = true;
            uni.showToast({
              title: openIdRes.data.msg,
              icon: 'none',
            });
            this.isLoading = false;
          }
        },
        fail: () => {
          this.repeat_click = true;
          uni.showToast({
            title: '服务器开小差，请稍后~',
            icon: 'none',
          });
          return false;
        },
      });
    },

    user_edit_company() {
      uni.navigateTo({
        url: '../user/user_edit_company',
      });
    },

    navigateBack() {
      uni.navigateBack();
    },
  },
  onLoad() {
    // autotextarea();
  },
};
</script>

<style>
.content * {
  float: right;
}
.tophr {
  width: 100%;
  height: 88rpx;
}
.addi {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  background: #ffffff;
  box-shadow: inset 0px 1px 0px #dddddd, inset 0px -1px 0px #dddddd;
  margin: 20rpx 0 0;
}
.addi text {
  width: auto;
  height: 90rpx;
  display: block;
  float: left;
  line-height: 90rpx;
  font-size: 34rpx;
  color: #000000;
  margin: 0 0 0 30rpx;
}
.addi input {
  width: 420rpx;
  height: 50rpx;
  display: block;
  float: right;
  margin: 20rpx 30rpx 0 0;
  text-align: right;
  line-height: 50rpx;
  font-size: 34rpx;
  color: #999999;
}
.addb {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  background: #ffffff;
  border: 1px solid #dddddd;
  border-left: 0;
  border-right: 0;
  margin: 20rpx 0 0;
}
.addbi {
  width: 720rpx;
  margin: 0 0 0 30rpx;
  height: 90rpx;
  display: block;
  float: left;
  background: #ffffff;
  border-bottom: 1px solid #dddddd;
}
.addb .addbi:last-child {
  border: none;
}
.addbi .addbil {
  width: auto;
  height: 90rpx;
  display: block;
  float: left;
  line-height: 90rpx;
  font-size: 34rpx;
  color: #000000;
}
.addbi .addbir {
  width: auto;
  height: 90rpx;
  display: block;
  float: right;
  line-height: 90rpx;
  font-size: 32rpx;
  color: #999999;
}
.addbi image {
  width: 16rpx;
  height: 25rpx;
  display: block;
  float: right;
  margin: 33rpx 30rpx 0 30rpx;
}
.addi textarea {
  width: 690rpx;

  height: 150rpx;
  display: block;
  float: left;
  margin: 0rpx 30rpx 20rpx;
  text-align: left;
  line-height: 40rpx;
  font-size: 34rpx;
  color: #999999;
}

.index {
  background: rgb(242, 242, 242);
  width: 100%;
  height: auto;
}
.jtop {
  width: 100%;
  height: 88rpx;
  background: #ffffff;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1000;
  box-shadow: inset 0px -1px 0px #dddddd;
}
.jtop_l {
  width: auto;
  height: 88rpx;
  display: block;
  float: left;
  font-size: 32rpx;
  color: #000000;
  line-height: 88rpx;
  margin: 0 0 0 30rpx;
}
.jtop_r {
  width: auto;
  height: 88rpx;
  display: block;
  float: right;
  margin: 0rpx 20rpx 0 0;
  line-height: 88rpx;
  font-size: 32rpx;
  color: #000000;
  color: #256aff;
}
.jtop_r.no {
  opacity: 0.5;
}
.jtop_r image {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: left;
}
.jtop_c {
  width: 70%;
  height: 48rpx;
  line-height: 48rpx;
  display: block;
  float: left;
  position: fixed;
  top: 20rpx;
  left: 15%;
  text-align: center;
  font-size: 36rpx;
  color: #000000;
}
.jtop_c image {
  width: 36rpx;
  height: 36rpx;
  display: inline-block;
  float: none;
  margin-bottom: -5rpx;
  margin-left: 5rpx;
}
.jtop_b {
  width: 100%;
  height: auto;
  background: #ffffff;
  position: fixed;
  top: 88rpx;
  left: 0;
  z-index: 1001;
}
.jtop_bj {
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  position: fixed;
  top: 0;
  left: 0;
  z-index: 999;
}

.jtop_bs {
  width: 100%;
  height: auto;
  background: #ffffff;
  display: block;
  float: left;
}
.jtop_bs view {
  width: 720rpx;
  height: 90rpx;
  background: #ffffff;
  display: block;
  float: left;
  margin: 0 0 0 30rpx;
  border-bottom: 1px solid #dddddd;
}
.jtop_bs view text {
  width: 80%;
  height: 90rpx;
  line-height: 90rpx;
  background: #ffffff;
  display: block;
  float: left;
  font-size: 34rpx;
  color: #000000;
}
.jtop_bs view image {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: right;
  margin: 21rpx 30rpx 0 0;
}
.jtop_tc {
  display: none;
}
.ellipsis-1 span {
  color: #999999;
}
</style>
